﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using ContractManager.Common.Class;
using ContractManager.Entity;
using Speed.Data;

namespace ContractManager.BLL.Business
{
    public static class ClsVoucherLock
    {

        public static List<VoucherLock> SelectAll()
        {
            using (var db = Sys.NewDb())
            {
                return Data.Base.VoucherLock.Select(db);
            }

        }

        public static List<DateTime> GetLockByFormNo(int formNo)
        {
            string commandText = String.Format("EXEC dbo.usp_GetLockDateByFormNo {0},{1}",ClsVariable.AsSysMyCoYearId, formNo);
            var lstTable = new List<DateTime>();
            using (var db = Sys.NewDb())
            {
                DataTable dt = db.ExecuteDataTable(commandText);
                dt.BeginLoadData();
                lstTable.AddRange(from DataRow row in dt.Rows select Convert.ToDateTime(row["StartTime"]).Date);
                dt.EndLoadData();
                return lstTable;
            }
        }


        public static void Insert(VoucherLock capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Insert<VoucherLock>(capital, EnumSaveMode.Requery);
            }

        }

        public static void Update(VoucherLock capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Update<VoucherLock>(capital);
            }

        }

        public static VoucherLock SelectByPk(Int32 workId)
        {
            using (var db = Sys.NewDb())
            {
                return db.SelectSingle<VoucherLock>(string.Format("VoucherLockId={0}", workId));
            }

        }

        
        public static int DeleteByPk(Int32 workId)
        {
            using (var db = Sys.NewDb())
            {
                return db.Delete<VoucherLock>(string.Format("VoucherLockId={0}", workId));
            }

        }

        
    }
}